package com.cskaoyan.controller;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.market.Issue;
import com.cskaoyan.bean.market.IssueList;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.market.IssueCreateVo;

import com.cskaoyan.service.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 商场管理模块 通用问题单元
 * 赵维虎
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {

    @Autowired
    IssueService issueService;


    @GetMapping("list")
    public BaseRespVo list(BaseParam baseParam, String question) {
        IssueList issueList = issueService.list(baseParam,question);
        return BaseRespVo.ok(issueList);
    }

    @PostMapping("create")
    public BaseRespVo create(@RequestBody Map map) {
        IssueCreateVo issueCreateVo = issueService.create(map);
        /*if(issueCreateVo == null){
            return BaseRespVo.fail("已回复过该问题！");
        }*/
        return BaseRespVo.ok(issueCreateVo);
    }

    @PostMapping("update")
    public BaseRespVo update(@RequestBody Issue issue){
        IssueCreateVo issueCreateVo = issueService.update(issue);
        return BaseRespVo.ok(issueCreateVo);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Issue issue){
        issueService.delete(issue);
        return BaseRespVo.ok();
    }
}
